package com.xpgk.mvc.ddc.maintenance.plateMaintenance;

import org.apache.commons.lang.StringUtils;

import com.jfinal.aop.Before;
import com.jfinal.plugin.activerecord.tx.Tx;
import com.xpgk.dto.RenderBean;
import com.xpgk.mvc.base.BaseController;

public class PlateMaintenanceController extends BaseController{

	private PlateMaintenanceService plateMaintenanceService;
	public void index(){
		render("plateMaintenance.html");
	}
	
	/**
	 * 车牌列表
	 */
	public void plateList(){
		String json = paging(splitPage, PlateMaintenance.sqlId_splitPageSelect, PlateMaintenance.sqlId_splitPageFrom);
		renderJson(json);
	}
	
	/**
	 * 跳转至添加产品
	 */
	public void toAddPlate(){
		render("addPlate.html");
	}
	
	/**
	 * 添加产品
	 */
	public void addPlate() {
		String ks = getPara("numberks");
		String js = getPara("numberjs");
		if (StringUtils.isNotBlank(ks) && StringUtils.isNotBlank(js)) {
			int ksnum = Integer.parseInt(ks);
			int jsnum = Integer.parseInt(js);
			for (int i = ksnum; i < (jsnum+1); i++) {
				PlateMaintenance p = getModel(PlateMaintenance.class);
				String newString = String.format("%04d", (i)); 
				p.set("carnumber", "晋BD"+newString);
				RenderBean renderBean = plateMaintenanceService.addPlate(p);
				renderJson(renderBean);
			}
		}
		/*RenderBean renderBean = plateMaintenanceService.addPlate(plateMaintenance);
		renderJson(renderBean);*/
	}
	
	/**
	 * 跳转至编辑
	 */
	public void toUpPlate(){
		PlateMaintenance plateMaintenance = PlateMaintenance.dao.findById(ids);
		setAttr("plateMaintenance", plateMaintenance);
		render("upPlate.html");
	}
	
	/**
	 * 编辑
	 */
	public void upPlate(){
		
		PlateMaintenance plateMaintenance = getModel(PlateMaintenance.class);
		RenderBean renderBean = plateMaintenanceService.upPlate(plateMaintenance);
		renderJson(renderBean);
	}
	
	/*
	 * 更该产品状态
	 */
	@Before(Tx.class)
	public void plateListstruts(){
		String ids = getPara("ids");
		PlateMaintenance plateMaintenance = PlateMaintenance.dao.findById(ids);
		plateMaintenance.set(PlateMaintenance.column_dataStatus,"0");
		boolean result = plateMaintenance.update();
		renderJson(result);
	}

	
}
